//
//  UIImageViewExtension.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/4.
//

import UIKit
import Kingfisher

extension UIImageView {
    /// 设置网络图片
    func wn_setupImg(_ img: String?, placeHolder: String?) {
        guard !isBlank(img) else {
            self.image = placeHolder != nil ? UIImage(named: placeHolder!) : nil
            return
        }

        self.kf.setImage(with: URL(string: img!), placeholder: placeHolder != nil ? UIImage(named: placeHolder!) : nil, options: nil, progressBlock: nil) { (result) in
        }
    }
    
    /// 设置网络图片带过度
    func wn_setupImgFade(_ img: String?, placeHolder: String?) {
        guard !isBlank(img) else {
            self.image = placeHolder != nil ? UIImage(named: placeHolder!) : nil
            return
        }
        kf.indicatorType = .activity
        self.kf.setImage(with: URL(string: img!), placeholder: placeHolder != nil ? UIImage(named: placeHolder!) : nil, options: [ .transition(.fade(1)), .scaleFactor(Screen.scale), .cacheOriginalImage], progressBlock: nil) { (result) in
        }
    }
}
